package imper.engine.util;

import imper.engine.entity.BuildFacilities;
import imper.engine.entity.CivilUnit;
import imper.engine.entity.Country;
import imper.engine.entity.Facilities;
import imper.engine.entity.GameMap;
import imper.engine.entity.Land;

public class CivilUnitUtil
{
	public static void produceCivilUnit(Country pCountry)
	{
		GameMap gameMap = ParameterManager.getInstance().getGameMap();
		for(CivilUnit civilUnit : pCountry.getCivilUnit())
		{
			if( civilUnit.getTurnOff() != 0)
			{
				civilUnit.setTurnOff(civilUnit.getTurnOff() - 1);
			}
			if( civilUnit.getBuildFacilities() != null &&  !civilUnit.getBuildFacilities().isEmpty() )
			{
				for(BuildFacilities buildFacilities: civilUnit.getBuildFacilities())
				{
					Land land = gameMap.getLand(buildFacilities.getPosX(), buildFacilities.getPosY());
					if( land != null)
					{
						Facilities facilities = new Facilities();
						facilities.setFacilitiesTypeId(buildFacilities.getFacilitiesId());
						land.getFacilities().add(facilities);
					}
				}
				civilUnit.setBuildFacilities(null);
			}
		}
	}
}
